
#ifndef _JOYSTICK_H_
#define _JOYSTICK_H_


#include <SDL/SDL.h>
#include <vector>

typedef SDL_Joystick * Joystickpointer;
typedef std::vector < Joystickpointer > Joysticklist;



struct Joystick {
	Joystickpointer _joystick;
	static int available() 		 { return SDL_NumJoysticks(); }
	static void enable_events()  { SDL_JoystickEventState(SDL_ENABLE); } 
	static Joystickpointer open(int number) { 
		if(number > available()) return NULL;
		return SDL_JoystickOpen(number);
	}
	static void close(Joystickpointer joy) {
		if(joy) SDL_JoystickClose(joy);
	}

	static void close_all(Joysticklist joylist) {
		for(int index =0; index < joylist.size() ; index++) {
			close(joylist[index]);
		}
	}	

	static Joysticklist open_all() { 
		Joysticklist result;
		for(int index =0; index < available(); index++) {
			Joystickpointer js = open(index);
			if (js) result.push_back(js); 
		}		
		return result;
	}

	static const char * name(int number)		{ return  SDL_JoystickName(number); 	}
	static int axe_count(Joystickpointer js) 	{ return  SDL_JoystickNumAxes(js); 		} 
 	static int button_count(Joystickpointer js) { return  SDL_JoystickNumButtons(js); 	} 

};


#endif
